﻿
using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using JumbotCms.Utils;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
#foreach($u in $TableInfos)
#beforeall
#each
    public partial class ${u.TabName}_ajax : JumbotCms.UI.AdminCenter
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CheckFormUrl())
            {
                Response.Write("提交有误");
                Response.End();
            }
            Admin_Load("0000", "json");
            this._operType = q("oper");
            switch (this._operType)
            {
                case "ajaxGetList":
                    ajaxGetList();
                    break;
                case "ajaxDel":
                    ajaxDel();
                    break;
                default:
                    DefaultResponse();
                    break;
            }
            Response.Write(this._response);
        }

       
        private void DefaultResponse()
        {
            this._response = JsonResult(0, "未知操作");
        }
        private void ajaxGetList()
        {
            string keys = q("keys");
            int pId = Str2Int(q("pId"), 0);
            int page = Int_ThisPage();
            int PSize = Str2Int(q("pagesize"), 20);
            int countNum = 0;
            string sqlStr = "";
            
            doh.Reset();
            doh.ConditionExpress = "zxftId=" + pId.ToString();
            countNum = doh.Count("${u.TabName}");
            sqlStr = JumbotCms.Utils.staticFunction.GetSql(" *", "${u.TabName}", "Id", PSize, page, "desc", "zxftId=" + pId.ToString());
            doh.Reset();
            doh.SqlCmd = sqlStr;
            DataTable dt = doh.GetDataTable();
            this._response = "{result :\"1\"," +
                "returnval :\"操作成功\"," +
                "pagerbar :\"" + JumbotCms.Utils.HtmlPager.GetPageBar(3, "js", 2, countNum, PSize, page, "javascript:ajaxList(<#page#>);") + "\"," +
                JumbotCms.Utils.JsonHelp.DtToSON(dt) +
                "}";
            dt.Clear();
            dt.Dispose();
        }
      
        private void ajaxDel()
        {
            string uId = f("id");

            doh.Reset();
            doh.ConditionExpress = "id=@id ";
            doh.AddConditionParameter("@id", uId);
            int _delCount = doh.Delete("${u.TabName}");

            if (_delCount > 0)
                this._response = JsonResult(1, "成功删除");
            else
                this._response = JsonResult(0, "删除失败");

        }
      
    }
}
#end